# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: db_test.py
  @time: 2022/6/15 11:06
  @desc:
"""
import random
import time

from database.entity.wafer import Wafer
from database.entity.chip import Chip
# from database.base import Base
# from db_helper1 import get_session, create_table
from ATS.proberdriver.cascade_prober import CascadeProber

if __name__ == '__main__':
    # print(Wafer.query([Chip], filter=[Wafer.wafer_name == "1234", Wafer.wafer_name == Chip.wafer_name]))
    # cp = CascadeProber(address="127.0.0.1")

    # map = cp.read_map_position()
    # print(map)
    wafer = Wafer("12345", f"4264", f"3", "1111", "中国", "30", "25")
    Wafer.metadata.create_all()
    # print(Wafer.query([Wafer]))
    wafer.add()
    curve = """[[-9.08919907, -9.0848999, -9.04957199, -9.02497101, -8.98638535, -8.92356873, -8.8744545, -8.80184555,
                  -8.71147919, -8.60570908, -8.5124321, -8.39268494, -8.27415466, -8.14289474, -8.03222656, -7.88957214,
                  -7.73913193, -7.63080978, -7.47746658, -7.34972763, -7.20752716, -7.06141663, -6.91664886, -6.79130936,
                  -6.6469574, -6.53589249, -6.4235611, -6.32133484, -6.23106003, -6.12214661, -6.06697083, -5.99433136,
                  -5.93268967, -5.9016037, -5.89847565, -5.92594147, -5.89371872, -5.92844772, -6.00233078, -6.09434891,
                  -6.18687057, -6.33893967, -6.53070068, -6.73267746, -6.98514175, -7.28982162, -7.66160965, -8.04912567,
                  -8.5358963, -9.09773254, -9.74087906, -10.468071, -11.3734474, -12.3973656, -13.640255, -15.2074471,
                  -17.2248802, -19.9455528, -23.9744453, -31.8622208, -34.1972351, -24.8091164, -20.096302, -17.1265182,
                  -14.8934402, -13.1363335, -11.7485199, -10.5730896, -9.58024979, -8.72902679, -8.02754974, -7.44799423,
                  -6.9564476, -6.59316254, -6.2959938, -6.08293152, -5.95881653, -5.89411163, -5.97293854, -6.09579849,
                  -6.37660217, -6.69395447, -7.174366, -7.79485703, -8.59584045, -9.58227539, -10.8422852, -12.4364738,
                  -14.6083488, -17.7839813, -22.8704376, -36.8083038, -26.1649513, -19.1702156, -15.4796181, -12.9370804,
                  -11.0646133, -9.60334396, -8.48013306, -7.59344864, -6.92137909],[-9.08919907, -9.0848999, -9.04957199, -9.02497101, -8.98638535, -8.92356873, -8.8744545, -8.80184555,
                  -8.71147919, -8.60570908, -8.5124321, -8.39268494, -8.27415466, -8.14289474, -8.03222656, -7.88957214,
                  -7.73913193, -7.63080978, -7.47746658, -7.34972763, -7.20752716, -7.06141663, -6.91664886, -6.79130936,
                  -6.6469574, -6.53589249, -6.4235611, -6.32133484, -6.23106003, -6.12214661, -6.06697083, -5.99433136,
                  -5.93268967, -5.9016037, -5.89847565, -5.92594147, -5.89371872, -5.92844772, -6.00233078, -6.09434891,
                  -6.18687057, -6.33893967, -6.53070068, -6.73267746, -6.98514175, -7.28982162, -7.66160965, -8.04912567,
                  -8.5358963, -9.09773254, -9.74087906, -10.468071, -11.3734474, -12.3973656, -13.640255, -15.2074471,
                  -17.2248802, -19.9455528, -23.9744453, -31.8622208, -34.1972351, -24.8091164, -20.096302, -17.1265182,
                  -14.8934402, -13.1363335, -11.7485199, -10.5730896, -9.58024979, -8.72902679, -8.02754974, -7.44799423,
                  -6.9564476, -6.59316254, -6.2959938, -6.08293152, -5.95881653, -5.89411163, -5.97293854, -6.09579849,
                  -6.37660217, -6.69395447, -7.174366, -7.79485703, -8.59584045, -9.58227539, -10.8422852, -12.4364738,
                  -14.6083488, -17.7839813, -22.8704376, -36.8083038, -26.1649513, -19.1702156, -15.4796181, -12.9370804,
                  -11.0646133, -9.60334396, -8.48013306, -7.59344864, -6.92137909]]"""
    #
    # for j in range(1000):
    # cp.step_first_die()
    # map = cp.read_map_position()
    # print(map)
    #

    # for i in range(1000):
    #     map = cp.read_map_position()
    #     # wafer = cp.get_wafer_info()
    #     chip = Chip("FR4-M4", "12345", f"{map.DieX},{map.DieY}", f"{map.CurDie}", f"{map.CurSite}", "TE",
    #                 "IR", f"{float(i) * random.randint(1,2)}", "ohm", "spot")
    #     chip.add()
    #     cp.step_next_die()
    #     time.sleep(0.5)
    # data_list = wafer.query([Chip], filter=[Chip.wafer_name == Wafer.wafer_name])
    # print(data_list)
